using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;using THSERP.BusinessEntities;using THSERP.BaseProvider;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraCharts;
using THSLib;using THSERP.BaseProvider;
namespace THSERP.Modules.Report
{
    public partial class RP007 : ReportForm
    {
        private ChartControl SaleComparisionChart;
        public enum AxisYChart { ExtPrice = 1, ExtCost = 2, Qty = 3 };
        public AxisYChart axisYChartType;
        public RP007()
        {
            InitializeComponent();
        }

        private void fld_btnApply_Click(object sender, EventArgs e)
        {
            ViewSaleComparisonChart();
        }

        private void fld_btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ViewSaleComparisonChart()
        {
            DateTime from = Convert.ToDateTime(fld_dteSearchFromARInvoiceDate.EditValue);
            DateTime to = Convert.ToDateTime(fld_dteSearchToARInvoiceDate.EditValue);
            String searchQuery = ((Modules.Report.ReportModule)this.Module).GenerateInvoiceItemSearchQuery(from, to, 0, 0, 0, 0, "i.FK_BRBranchID");

            ARInvoiceItemsController objInvoiceItemsController = new ARInvoiceItemsController();
            DataSet ds = objInvoiceItemsController.GetDataSet(searchQuery);
            List<double> lstTypeValue = new List<double>();
            SaleComparisionChart.Series[0].Points.Clear();

            foreach (DataRow row in ds.Tables[0].Rows)
            {

                ARInvoiceItemsInfo objInvoiceItemsInfo = (ARInvoiceItemsInfo)objInvoiceItemsController.GetObjectFromDataRow(row);
                BRBranchsInfo objBranchsInfo = (BRBranchsInfo)new BRBranchsController().GetObjectByID((int)row["FK_BRBranchID"]);
                SeriesPoint point = new SeriesPoint();
                switch (axisYChartType)
                {
                    case AxisYChart.ExtPrice:
                        point = new SeriesPoint(objBranchsInfo.BRBranchName, objInvoiceItemsInfo.ARInvoiceItemNetAmount);
                        lstTypeValue.Add(objInvoiceItemsInfo.ARInvoiceItemNetAmount);
                        break;
                    case AxisYChart.ExtCost:
                        point = new SeriesPoint(objBranchsInfo.BRBranchName, objInvoiceItemsInfo.ARInvoiceItemTotalCost);
                        lstTypeValue.Add(objInvoiceItemsInfo.ARInvoiceItemTotalCost);
                        break;
                    case AxisYChart.Qty:
                        point = new SeriesPoint(objBranchsInfo.BRBranchName, objInvoiceItemsInfo.ARInvoiceItemProductQty);
                        lstTypeValue.Add(objInvoiceItemsInfo.ARInvoiceItemProductQty);
                        break;
                }
                SaleComparisionChart.Series[0].Points.Add(point);
            }
        }

        private void fld_ctxItemExtPrice_Click(object sender, EventArgs e)
        {
            fld_lblAxisYChartType.Text = fld_ctxItemExtPrice.Text;
            axisYChartType = AxisYChart.ExtPrice;
            ViewSaleComparisonChart();
        }

        private void fld_ctxItemExtCost_Click(object sender, EventArgs e)
        {
            fld_lblAxisYChartType.Text = fld_ctxItemExtCost.Text;
            axisYChartType = AxisYChart.ExtCost;
            ViewSaleComparisonChart();
        }

        private void fld_ctxItemQty_Click(object sender, EventArgs e)
        {
            fld_lblAxisYChartType.Text = fld_ctxItemQty.Text;
            axisYChartType = AxisYChart.Qty;
            ViewSaleComparisonChart();
        }

        private void RP007_Load(object sender, EventArgs e)
        {
            SaleComparisionChart = fld_chcSaleComparison;
            axisYChartType = AxisYChart.ExtPrice;
            fld_lblAxisYChartType.Text = fld_ctxItemExtPrice.Text;
            ViewSaleComparisonChart();
        }
    }
}